package ${pPackage}.common.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@ApiModel(value = "Result", description = "响应数据")
public class Result<T> {

  @ApiModelProperty(value = "状态", example = "true")
  private boolean success;//是否成功

  @ApiModelProperty(value = "返回码", example = "000000")
  private Integer code;// 返回码

  @ApiModelProperty(value = "返回信息", example = "成功")
  private String message;//返回信息

  @ApiModelProperty(value = "返回数据")
  private T data;// 返回数据

  public Result(ResultCode code) {
    this.success = code.success;
    this.code = code.code;
    this.message = code.message;
  }

  public Result(ResultCode code, Object data) {
    this.success = code.success;
    this.code = code.code;
    this.message = code.message;
    this.data = (T) data;
  }

  public Result(Integer code, String message, boolean success) {
    this.code = code;
    this.message = message;
    this.success = success;
  }

  public static Result SUCCESS() {
    return new Result(ResultCode.E_000000);
  }

  public static Result SUCCESS(Object data) {
    return new Result(ResultCode.E_000000, data);
  }

  public static Result ERROR() {
    return new Result(ResultCode.UNKNOWN);
  }

  public static Result FAIL() {
    return new Result(ResultCode.E_100001);
  }

  public static Result FAIL(String message) {
    return new Result(100101, message, false);
  }

}

